/*
 * ImportGTFSDialog.java
 * 
 * Created by demory on Jul 14, 2009, 3:54:52 PM
 * 
 * Copyright 2008 David D. Emory
 * 
 * This file is part of Five Points. See <http://www.fpdev.org> for
 * additional information regarding the project.
 * 
 * Five Points is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Five Points is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Five Points.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.fpdev.apps.rtemaster.gui.dialogs;

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.border.CompoundBorder;
import javax.swing.border.EmptyBorder;
import javax.swing.border.TitledBorder;
import org.fpdev.core.transit.gtfs.GTFSImporter;
import org.fpdev.apps.rtemaster.gui.RMGUI;
import org.fpdev.util.gui.GUIFactory;

/**
 *
 * @author demory
 */
public class ImportGTFSDialog extends JDialog implements ActionListener {

  private GTFSImporter importer_;
  private JTextField fileField_;
  private JButton selectBtn_, importBtn_, cancelBtn_;

  private JTable table_;

  public ImportGTFSDialog(GTFSImporter importer, RMGUI gui) {
    super(gui, true);

    JPanel fileRow = new JPanel(new BorderLayout());
    fileField_ = GUIFactory.newTextField("(Select a directory)", 0, 0);
    selectBtn_ = GUIFactory.newButton("Select..", 80, this);
    fileRow.add(fileField_, BorderLayout.CENTER);
    fileRow.add(selectBtn_, BorderLayout.EAST);
    fileRow.setBorder(new CompoundBorder(new TitledBorder("GTFS Data Source"), new EmptyBorder(4,4,4,4)));

    JPanel tablePanel = new JPanel(new GridLayout(1,1));
    table_ = new JTable();
    tablePanel.add(new JScrollPane(table_));

    importBtn_ = GUIFactory.newButton("Import", 80, this);
    cancelBtn_ = GUIFactory.newButton("Cancel", 80, this);
    JPanel buttonRow = GUIFactory.newRowPanel();
    buttonRow.add(Box.createHorizontalGlue());
    buttonRow.add(importBtn_);
    buttonRow.add(Box.createHorizontalStrut(5));
    buttonRow.add(cancelBtn_);
    buttonRow.add(Box.createHorizontalGlue());
    buttonRow.setBorder(new EmptyBorder(5, 5, 5, 5));

    JPanel mainPanel = new JPanel(new BorderLayout());
    mainPanel.add(fileRow, BorderLayout.NORTH);
    mainPanel.add(tablePanel, BorderLayout.CENTER);
    mainPanel.add(buttonRow, BorderLayout.SOUTH);
    mainPanel.setBorder(new EmptyBorder(5,5,5,5));
    
    getContentPane().add(mainPanel);
    setSize(600,400);
    setLocationRelativeTo(null);

    setVisible(true);

  }

  public void actionPerformed(ActionEvent e) {
    if(e.getSource() == selectBtn_) {
      //importer_.setDirectory();
      refreshTable();
    }
    if(e.getSource() == cancelBtn_) {
      setVisible(false);
    }
  }

  public void refreshTable() {
    /*String[] colNames = new String[2];
    colNames[0] = "ID";
    colNames[1] = "Name";
    colNames[2] = "Patterns";

    String[][] table = new String[dps.size()][3];

    int r = 0;
    for (Iterator<DPPreview> it = dps.iterator(); it.hasNext();) {
      DPPreview dpp = it.next();
      table[r][0] = dpp.getName();
      table[r][1] = dpp.getDesc();
      r++;
    }
    DefaultTableModel model = new UneditableTableModel(table, colNames);
    setModel(model);*/

  }

}
